package soulkun.library.component

import android.content.Context
import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import soulkun.library.utils.screen.ScreenUtils

abstract class BaseActivity(private val isNeedTranslucentStatusBar: Boolean) : AppCompatActivity() {

    companion object {
        var TAG = "BaseActivity"
    }

    protected lateinit var mContext: Context
    protected lateinit var mActivity: AppCompatActivity

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        TAG = "TAG:" + javaClass.simpleName
        if (application is MonitorApplication) {
            (application as MonitorApplication).addActivity(this)
        }
        mContext = this
        mActivity = this
        if (isNeedTranslucentStatusBar) initTheme()
        setContentView(setLayout())
        initIntent()
        initView()
        initData()
        initListener()
    }

    @LayoutRes
    protected abstract fun setLayout(): Int

    //状态栏透明
    protected fun initTheme() {
        ScreenUtils.setTranslucentStatusBar(this)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        val actionBar = supportActionBar
        actionBar?.hide()
    }

    protected abstract fun initIntent()

    protected abstract fun initView()

    protected abstract fun initData()

    protected abstract fun initListener()

    override fun onDestroy() {
        if (application is MonitorApplication) {
            (application as MonitorApplication).removeActivity(this)
        }
        super.onDestroy()
    }

}